package com.myz.app.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * redis操作工具
 *
 * @author maoyz on 18-3-12.
 */
public class RedisUtil {


  @Autowired
  private RedisTemplate redisTemplate;

  private final String shiro_prefiex = "shiro_redis_session:";


  public void set(String key, String val) {
    redisTemplate.opsForValue().set(key, val);
  }

  public void set(byte[] key, byte[] val, long expire) {
    redisTemplate.opsForValue().set(key, val, expire);
  }

  public void set(String key, String val, long expire) {
    redisTemplate.opsForValue().set(key, val, expire);
  }

  public Object get(String key) {
    return redisTemplate.opsForValue().get(key);
  }


  public byte[] get(byte[] key) {
    return (byte[]) redisTemplate.opsForValue().get(key);
  }

  public Long getExpire(String key){
    return redisTemplate.getExpire(key);
  }


  public RedisTemplate getRedisTemplate() {
    return redisTemplate;
  }

  public void setRedisTemplate(RedisTemplate redisTemplate) {
    this.redisTemplate = redisTemplate;
  }

  public void del(byte[] key) {
    redisTemplate.delete(key);
  }
}
